<template>
  <!-- 辅导员信息申请 -->
  <div class="app-container">
    <selectCounselors ref="selectUserRef" :sendUserIds.sync="sendUserIds" :cId="cId"></selectCounselors>
    <!-- 添加或修改角色配置对话框 -->
    <el-form ref="form" :model="form" :rules="rules" label-width="95px">
      <el-row>
        <!-- <el-col :span="8">
          <el-form-item label="所属院系" prop="deptId">
            <el-cascader clearable
            v-model="form.deptId"
            :options="deptOptions"
            :props="{ value: 'id',currentLabels: 'label',checkStrictly: true}"
            @change="handleChange"
            style="width: 100%;"
          ></el-cascader>
          <el-select v-model="form.deptId" placeholder="请选择" clearable class="elSelect" @change="handleChange"  style="width: 100%">
            <el-option v-for="item in deptOptions" :key="item.deptId" :label="item.deptName"
              :value="item.deptId"></el-option>
          </el-select>
          </el-form-item>
        </el-col> -->
        <el-col :span="8">
          <el-form-item label="来校日期" prop="admissionTime">
            <el-date-picker clearable 
              v-model="form.admissionTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择来校日期"
              style="width: 100%"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="工号" prop="tno">
            <el-input v-model.trim="form.tno" clearable placeholder="请输入工号" maxlength="30" disabled/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="姓名" prop="name">
            <el-input v-model.trim="form.name" clearable placeholder="请输入姓名" maxlength="10" disabled/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="性别" prop="sex">
            <el-select v-model="form.sex" clearable placeholder="请选择性别" style="width: 100%">
              <el-option
                v-for="dict in dict.type.sys_user_sex"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="在职状态" prop="postStatus">
            <el-select
              v-model="form.postStatus"
              clearable
              placeholder="请选择在职状态"
              style="width: 100%"
            >
              <el-option
                v-for="dict in dict.type.basic_post_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="血型" prop="bloodType">
            <el-select clearable v-model="form.bloodType" placeholder="请选择血型" style="width: 100%">
              <el-option
                v-for="dict in dict.type.basic_blood_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="身份证件号" prop="cardCode">
            <el-input
              v-model.trim="form.cardCode"
              placeholder="请输入身份证件号"
              clearable
              maxlength="18"
              @blur="codeBulr"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="出生日期" prop="birthday">
            <el-date-picker clearable 
              v-model="form.birthday"
              disabled
              type="date"
              placeholder="选择出生日期"
              style="width: 100%"
              value-format="yyyy-MM-dd"
              format="yyyy-MM-dd"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="联系方式" prop="phone">
            <el-input v-model.trim="form.phone" clearable placeholder="请输入联系方式" maxlength="11" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="民族" prop="nation">
            <el-select v-model="form.nation" clearable placeholder="请选择民族" style="width: 100%">
              <el-option
                v-for="dict in dict.type.bc_nation_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="政治面貌" prop="political">
            <el-select v-model="form.political" clearable placeholder="请选择政治面貌" style="width: 100%">
              <el-option
                v-for="dict in dict.type.bc_political_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="曾用名" prop="formerName">
            <el-input v-model.trim="form.formerName" clearable placeholder="请输入曾用名" maxlength="10" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="籍贯" prop="birthplace">
        
          <el-cascader v-model="form.birthplace" clearable style="width: 100%;"
                :props="{ value: 'unitCode',currentLabels: 'label', checkStrictly: true }"
                 :options="options" @change="handlePlace"></el-cascader>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="职称" prop="title">
            <el-select v-model="form.title" clearable placeholder="请选择职称" style="width: 100%">
              <el-option
                v-for="dict in dict.type.basic_title_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="职称级别" prop="titleLevel">
            <el-select v-model="form.titleLevel" clearable placeholder="请选择职称级别" style="width: 100%">
              <el-option
                v-for="dict in dict.type.basic_title_level"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="角色" prop="roles" v-if="this.cId ? false: true">
            <el-select v-model="form.roles" clearable placeholder="请选择角色" style="width: 100%;">
                <el-option
                  v-for="item in roleOptions"
                  :key="item.roleId"
                  :label="item.roleName"
                  :value="item"
                  :disabled="item.status == 1"
                ></el-option>
              </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    
    <h2>工作经历</h2>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAddClrWorkHistory"
        >添加</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDeleteClrWorkHistory"
        >删除</el-button>
      </el-col>
    </el-row>
    <el-table
      :data="clrWorkHistoryList"
      @selection-change="handleClrWorkHistorySelectionChange"
      ref="clrWorkHistory"
    >
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column label="序号" align="center" type="index" width="50" />
      <el-table-column label="公司名称" prop="cName" align="center"></el-table-column>
      <el-table-column label="开始时间" prop="startDate" align="center"></el-table-column>
      <el-table-column label="结束时间" prop="endDate" align="center"></el-table-column>
      <el-table-column label="职位名称" prop="jobTitle" align="center"></el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="workDetails(scope.row)"
            v-hasPermi="['system:role:details']"
          >查看详情</el-button>
          <el-button
            type="text"
            icon="el-icon-delete"
            size="mini"
            @click="handleDeleteClrWorkHistory(scope.$index, clrWorkHistoryList)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      width="50%"
      title="工作经历"
      :visible.sync="innerVisible"
      append-to-body
      destroy-on-close
    >
      <el-form ref="formWork" :model="formWork" :rules="workRules" label-width="90px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="公司名称" prop="cName">
              <el-input v-model="formWork.cName" clearable placeholder="请输入公司名称" maxlength="30" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="职位名称" prop="jobTitle">
              <el-input v-model="formWork.jobTitle" clearable placeholder="请输入职位名称" maxlength="30" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="起止时间">
              <el-date-picker
                v-model="dataTime" clearable 
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                @change="dateTimes"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="工作内容" prop="workContent">
              <editor v-model="formWork.workContent" :min-height="180" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="工作业绩" prop="workPerformance">
              <editor v-model="formWork.workPerformance" :min-height="180" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitWork" :disabled="workDisabled">确 定</el-button>
        <el-button @click="innerVisible = false">取 消</el-button>
      </div>
    </el-dialog>
    <h2>教育背景</h2>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-plus" size="mini" @click="educationalAdd">添加</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multipleEducation"
          @click="handleDeleteClrEducationHistory"
        >删除</el-button>
      </el-col>
    </el-row>
    <!-- <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="educationalVisible = true">新增</el-button> -->
    <el-table :data="clrEducationList" @selection-change="handleClrEducationSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="学历" prop="education" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.basic_education_type" :value="scope.row.education" />
        </template>
      </el-table-column>
      <el-table-column label="毕业学校" prop="sName" :show-overflow-tooltip="true" align="center" />
      <el-table-column label="毕业专业" prop="gMajor" :show-overflow-tooltip="true" align="center" />
      <el-table-column label="学习方式" prop="lStyle" :show-overflow-tooltip="true" align="center">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.clr_learning_style" :value="scope.row.lStyle" />
        </template>
      </el-table-column>
      <el-table-column label="学制" prop="eSystem" :show-overflow-tooltip="true" align="center">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bc_speciality_type" :value="scope.row.eSystem" />
        </template>
      </el-table-column>
      <el-table-column label="毕业时间" prop="endDate" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="educationDetails(scope.row)"
            v-hasPermi="['system:role:details']"
          >查看详情</el-button>
          <el-button
            type="text"
            icon="el-icon-delete"
            size="mini"
            @click="handleDeleteClrEducationHistory(scope.$index, clrEducationList)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <h2>班级选择</h2>
    <el-badge :value="sendUserIds.length" :hidden="!sendUserIds.length" :type="'primary'">
              <el-button size="small" @click="selectUserBtn">选择</el-button>
            </el-badge>
    <el-dialog
      width="50%"
      title="教育背景"
      :visible.sync="educationalVisible"
      append-to-body
      destroy-on-close
    >
      <el-form ref="educationFrom" :model="educationFrom" :rules="educationRole" label-width="29%">
        <el-row>
          <el-col :span="12">
            <el-form-item label="学历" prop="education">
              <el-select v-model="educationFrom.education" clearable placeholder="请选择" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.basic_education_type"
                  :key="dict.index"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="毕业学校" prop="sName">
              <el-input v-model="educationFrom.sName" clearable placeholder="请输入毕业学校" maxlength="30" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学校类型" prop="sType">
              <el-select v-model="educationFrom.sType" clearable placeholder="请选择" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.clr_school_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="授予国家或地区" prop="educationCountry">
              <el-select
                v-model="educationFrom.educationCountry" clearable 
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in dict.type.clr_country_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="入校时间" prop="startDate">
              <el-date-picker
                v-model="educationFrom.startDate" clearable 
                type="date"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="毕业时间" prop="endDate">
              <el-date-picker v-model="educationFrom.endDate" clearable type="date" value-format="yyyy-MM-dd"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学科" prop="discipline">
              <el-input v-model="educationFrom.discipline" clearable placeholder="请输入学科" maxlength="30" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="毕业专业" prop="gMajor">
              <el-input v-model="educationFrom.gMajor" clearable placeholder="请输入毕业专业" maxlength="30" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学习形式" prop="lModality">
              <el-select v-model="educationFrom.lModality" clearable placeholder="请选择" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.clr_learning_forms"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学习方式" prop="lStyle">
              <el-select v-model="educationFrom.lStyle" clearable placeholder="请选择" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.clr_learning_style"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学制" prop="eSystem">
              <el-select v-model="educationFrom.eSystem" placeholder="请选择" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.bc_speciality_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否最高学历" prop="isEducation">
              <el-select v-model="educationFrom.isEducation" clearable placeholder="请选择" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学位类型" prop="degreeType">
              <el-select v-model="educationFrom.degreeType" clearable placeholder="请选择" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.basic_degree_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学位授予国家" prop="degreeCountry">
              <el-select
                v-model="educationFrom.degreeCountry" clearable 
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in dict.type.clr_country_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学位授予单位" prop="degreeUnit">
              <el-input v-model="educationFrom.degreeUnit" clearable placeholder="请输入学位授予单位" maxlength="30" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学位授予日期" prop="degreeDate">
              <el-date-picker
                v-model="educationFrom.degreeDate" clearable 
                type="date"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否最高学位" prop="isDegree">
              <el-select v-model="educationFrom.isDegree" clearable placeholder="请选择" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学位专业" prop="degreeMajor">
              <el-input v-model="educationFrom.degreeMajor" clearable placeholder="请输入学位专业" maxlength="30" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitEducation" :disabled="educationDisabled">确 定</el-button>
        <el-button @click="educationalCancel">取 消</el-button>
      </div>
    </el-dialog>
    <div style="text-align: center;margin-top:10px">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </div>
</template>

<script>
import { addApprclrinfo } from "@/api/clr/apprclrinfo";
import { listRole } from "@/api/system/role"; 

import { getUser,deptTreeSelect } from "@/api/system/user";
import { counsellorInforTid } from "@/api/counselor/index";
import selectCounselors from "@/views/apply/components/selectCounselors.vue";
import Validators from "@/utils/validate.js";
import { getProvinceTree } from "@/api/information/classInfor";
import {
  collegeSelect
} from "@/api/information/studentInfor"
// import { listRole, getRole, delRole, addRole, updateRole, dataScope, changeRoleStatus, deptTreeSelect } from "@/api/system/role";
export default {
  name: "Apprclrinfo",
  components: {
    selectCounselors
  },
  dicts: [
    "clr_appr_status",
    "basic_education_type", // 学历类型
    "basic_degree_type", // 学位类型
    "sys_user_sex", // 性别
    "bc_political_type", // 政治面貌
    "bc_nation_type", // 民族类型
    "clr_counsellor_type", // 是否辅导员
    "clr_cthr_type", // 是否班主任
    "bc_office_type", // 任职类型
    "basic_post_status", //在岗状态
    "clr_learning_style", //学习方式
    "clr_learning_forms", //学习形式
    "clr_school_type", //学校类型
    "sys_yes_no", //学位类型
    "basic_blood_type", // 血型
    "basic_title_type", // 职称类型
    "basic_title_level", // 职称级别
    "clr_country_type", // 授予国家
    "bc_speciality_type" //学制类型
  ],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedClrApprRecord: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 辅导员信息申请单表格数据
      apprclrinfoList: [],
      // 辅导员审批记录表格数据
      clrApprRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      deptOptions: [],
      options:[], // 籍贯
      clrEducationList: [], //
      formWork: {},
      clrWorkHistoryList: [],
      educationSname: [],
      dataTime: [],
      innerVisible: false, // 添加工作经历弹窗
      educationalVisible: false, // 教育背景弹窗
      workDisabled: false,
      educationDisabled: false,
      multipleEducation: true,
      sendUserIds: [],
      roleOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        applyTno: null,
        applyName: null,
        applyTime: null,
        applyRule: null,
        apprStatus: null
      },
      // 表单参数
      form: {
        teacher: {},
        deptId: "",
      },
      cId: "", //教师ID
      type: null, // 调整类型（A:新增信息,E:修改信息）
      educationFrom: {},
      // 表单校验
      rules: {
        // deptId: [
        //   { required: true, message: "请选择所属院系", trigger: "change" }
        // ],
        admissionTime: [
          { required: true, message: "请选择来校时间", trigger: "change" }
        ],
        postStatus: [
          { required: true, message: "请选择岗位状态", trigger: "change" }
        ],
        tno: [
          {
            required: true,
            text: "请输入工号",
            validator: Validators.istext,
            trigger: "blur"
          }
        ],
        name: [
          {
            required: true,
            text: "请输入姓名",
            validator: Validators.isString,
            trigger: "blur"
          }
        ],
        sex: [{ required: true, message: "请选择性别", trigger: "change" }],
        bloodType: [
          { required: false, message: "请选择血型", trigger: "change" }
        ],
        cardCode: [
          { required: true, message: "请输入身份证号", trigger: "blur" },
          {
            message: "请输入正确的身份证号",
            pattern: /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]+$/,
            trigger: "blur"
          }
        ],
        phone: [
          { required: true, message: "请输入联系方式", trigger: "blur" },
          {
            message: "请输入正确的身份证号",
            pattern: /^1\d{10}$/,
            trigger: "blur"
          }
        ],
        birthday: [
          { required: true, message: "请选择出生日期", trigger: "change" }
        ],
        nation: [{ required: true, message: "请选择民族", trigger: "change" }],
        political: [
          { required: true, message: "请选择政治面貌", trigger: "change" }
        ],
        formerName: [
          {
            required: false,
            text: "请输入曾用名",
            // validator: Validators.isString,
            trigger: "blur"
          }
        ],
        birthplace: [
          { required: true, message: "请选择籍贯", trigger: "change" },
       
        ],
       
        title: [{ required: true, message: "请选择职称", trigger: "change" }],
        titleLevel: [
          { required: true, message: "请选择职称级别", trigger: "change" }
        ],
        roles: [
          { required: true, message: "请选择角色", trigger: "change" }
        ],
      },
      workRules: {
        cName: [{ required: true, message: "请输入公司名称", trigger: "bulr" }],
        jobTitle: [
          { required: true, message: "请输入职务名称", trigger: "bulr" }
        ],
        startDate: [
          { required: true, message: "请选择时间", trigger: "change" }
        ],
        endDate: [{ required: true, message: "请选择时间", trigger: "change" }]
      },
      educationRole: {
        education: [
          { required: true, message: "请选择学历", trigger: "change" }
        ],
        sName: [{ required: true, message: "请输入毕业学校", trigger: "bulr" }],
        gMajor: [
          { required: true, message: "请输入毕业专业", trigger: "bulr" }
        ],
        startDate: [
          { required: true, message: "请选择入校时间", trigger: "change" }
        ],
        endDate: [
          { required: true, message: "请选择毕业时间", trigger: "change" }
        ],
        lStyle: [
          { required: true, message: "请选择学习方式", trigger: "change" }
        ],
        eSystem: [{ required: true, message: "请选择学制", trigger: "change" }],
        isEducation: [{ required: true, message: "请选择是否最高学历", trigger: "change" }],
        isDegree: [{ required: true, message: "请选择是否最高学位", trigger: "change" }],
      }
    };
  },
  mounted() {
    this.department();
    this.form = {...this.userInfor.teacher};
   if(this.form.id){
    // 查询辅导员信息列表
    counsellorInforTid(this.form.id).then(res => {
      if (res.data) {
        this.cId = res.data.cId;
        this.clrEducationList = res.data.clrEducationList;
        this.clrWorkHistoryList = res.data.clrWorkHistoryList;
        this.form.birthplace = res.data.teacher.birthplace;
        this.sendUserIds = res.data.classList;
        console.log(res, "lllll");
        this.form = res.data.teacher;
      }else {
        getUser().then(response => {
        this.roleOptions = response.roles.filter(item =>  {
          return item.roleName == '辅导员'
        });;
      });
      }
      console.log(this.cId,'dsadhskaj')
    });
   }
    
   
     // 籍贯下拉书
      getProvinceTree().then(response => {
        this.options = response.data
      
      });

  },
  computed: {
    userInfor() {
      return this.$store.state.user.userInfor;
    }
  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
    },
    // 清除表单
    CloseIn() {
      this.form = {};
      this.formTeacher = {};
      this.open = false;
    },

    handleChange(value) {
      if (value) {
        this.form.deptId = value
      }
      // this.form.deptId = value[2];
      // this.form.multistage = value + "";
    },
    // 根据身份证号获取出生年月
    codeBulr() {
      if (this.form.cardCode) {
        this.$set(this.form, "birthday", this.getBirthday(this.form.cardCode));
      }
    },
    // 弹窗取消
    educationalCancel() {
      this.educationalVisible = false;
      this.resetForm("educationFrom");
    },
    // 获取部门信息
    async department() {
      await deptTreeSelect().then(res => {
        this.deptOptions = res.data;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.caiId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    // 添加工作经历
    handleAddClrWorkHistory() {
      this.innerVisible = true;
      this.workDisabled = false;
      this.formWork = {};
    },
    handlePlace(data) {
      this.form.birthplace = data[data.length - 1]

    },
    // 添加教育背景
    educationalAdd() {
      this.educationalVisible = true;
      this.educationDisabled = false;
      this.educationFrom = {};
    },
    // 起止时间
    dateTimes() {
      console.log(this.dataTime, "dateTime");
      this.formWork.startDate = this.dataTime[0];
      this.formWork.endDate = this.dataTime[1];
    },
    // 工作经历
    submitWork() {
      console.log(this.dataTime, "submitWork");
      if (this.dataTime.length == 0) {
        this.$modal.msgWarning("请选择时间");
      } else {
        if (this.clrWorkHistoryList.length > 0) {
          this.clrWorkHistoryList.forEach(element => {
            if (element.cName == this.formWork.cName) {
              this.$modal.msgWarning("添加的工作单位已存在");
            } else {
              this.$refs["formWork"].validate(valid => {
                if (valid) {
                  this.clrWorkHistoryList = this.clrWorkHistoryList;
                  this.clrWorkHistoryList.push(this.formWork);
                  this.dataTime = [];
                  this.formWork = {};
                  this.innerVisible = false;
                }
              });
            }
          });
        } else {
          this.$refs["formWork"].validate(valid => {
            if (valid) {
              this.clrWorkHistoryList = this.clrWorkHistoryList;
              this.clrWorkHistoryList.push(this.formWork);
              this.dataTime = [];
              this.formWork = {};
              this.innerVisible = false;
            }
          });
        }
      }
    },
    selectUserBtn() {
      this.$refs.selectUserRef.open();
    },
    // 工作经历多选
    handleClrWorkHistorySelectionChange(selection) {
      this.workCname = selection;
      this.multiple = !selection.length;
    },
    // 教育背景多选
    handleClrEducationSelectionChange(selection) {
      this.educationSname = selection;
      this.multipleEducation = !selection.length;
    },
    // 教育背景参数添加
    submitEducation() {
      if (this.clrEducationList.length > 0 ) {
        this.clrEducationList.forEach(element => {
          if (element.sName == this.educationFrom.sName) {
            this.$modal.msgWarning("添加的学校已存在");
          } else if((element.isDegree == 'Y' && this.educationFrom.isDegree == 'Y')||(element.isEducation == 'Y' && this.educationFrom.isEducation == 'Y')){
            this.$modal.msgWarning("最高学历或最高学位已存在");
          } else {
            this.$refs["educationFrom"].validate(valid => {
              if (valid) {
                this.clrEducationList = this.clrEducationList;
                this.clrEducationList.push(this.educationFrom);
                this.educationalVisible = false;
                this.educationFrom = {};
              } else {
              }
            });
          }
        });
      } else {
        this.$refs["educationFrom"].validate(valid => {
          if (valid) {
            this.clrEducationList = this.clrEducationList;
            console.log(this.educationFrom, "push");
            this.clrEducationList.push(this.educationFrom);
            console.log(this.clrEducationList, "添加");

            this.educationalVisible = false;
            this.educationFrom = {};
          } else {
          }
        });
      }
    },
    // 删除工作经历
    handleDeleteClrWorkHistory(index, rows) {
      console.log(index,rows)
        if(rows) {
         rows.splice(index, 1);
      }else {
      this.clrWorkHistoryList = this.clrWorkHistoryList.filter(
        item => !this.workCname.some(it => it.cName === item.cName)
      );
      }
    },
    // 删除教育背景
    handleDeleteClrEducationHistory(index, rows) {
      if(rows) {
         rows.splice(index, 1);
      }else {
      this.clrEducationList = this.educationSname.filter(
        item => !this.educationSname.some(it => it.sName === item.sName)
      );
      }
    
    },
    // 教育背景查看详情
    educationDetails(row) {
      this.educationFrom = row;

      this.educationalVisible = true;
      this.educationDisabled = true;
    },
    /** 提交按钮 */
    submitForm() {
      this.sendUserIds = this.sendUserIds.map(i => {
        return {
          classId: i.id,
          ...i
        };
      });
      this.$refs["form"].validate(valid => {
        if (valid) {
          let data = {
            teacher: {},
            clrWorkHistoryList: [],
            clrEducationList: [],
            classList: this.sendUserIds
          };
          data.teacher = this.form;

          data.clrWorkHistoryList = this.clrWorkHistoryList;
          data.clrEducationList = this.clrEducationList;
          if (this.cId == '' || this.cId == null) {
            this.type = "A";
            data.tId = this.form.id;
          } else {
            this.type = "E";
            data.cId = this.cId;
            data.tId = this.form.id;
          }
          addApprclrinfo({
            applyRule: this.type,
            parameter: JSON.stringify(data)
          }).then(response => {
            this.$modal.msgSuccess("信息提交成功");
            this.$router.push({ path: "/counselor/clrApply/apprclrinfo" });
          });
        }
      });
    },
    /** 辅导员审批记录序号 */
    rowClrApprRecordIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 辅导员审批记录添加按钮操作 */
    handleAddClrApprRecord() {
      let obj = {};
      obj.confSeq = "";
      obj.apprTno = "";
      obj.apprName = "";
      obj.apprRole = "";
      obj.apprTime = "";
      obj.apprStatus = "";
      this.clrApprRecordList.push(obj);
    },
    /** 辅导员审批记录删除按钮操作 */
    handleDeleteClrApprRecord() {
      if (this.checkedClrApprRecord.length == 0) {
        this.$modal.msgError("请先选择要删除的辅导员审批记录数据");
      } else {
        const clrApprRecordList = this.clrApprRecordList;
        const checkedClrApprRecord = this.checkedClrApprRecord;
        this.clrApprRecordList = clrApprRecordList.filter(function(item) {
          return checkedClrApprRecord.indexOf(item.index) == -1;
        });
      }
    },
    /** 复选框选中数据 */
    handleClrApprRecordSelectionChange(selection) {
      this.checkedClrApprRecord = selection.map(item => item.index);
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "clr/apprclrinfo/export",
        {
          ...this.queryParams
        },
        `apprclrinfo_${new Date().getTime()}.xlsx`
      );
    }
  }
};
</script>
